<html>
<head><meta charset="utf-8"><title>adding a note to borrow-check error · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/adding.20a.20note.20to.20borrow-check.20error.html">adding a note to borrow-check error</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212982589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/adding%20a%20note%20to%20borrow-check%20error/near/212982589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/adding.20a.20note.20to.20borrow-check.20error.html#212982589">(Oct 11 2020 at 21:30)</a>:</h4>
<p>I want to implement <a href="https://github.com/rust-lang/rust/issues/77834">#77834</a>, which is my idea for adding a help message to a borrow-check error that can be easily fixed by using a temporary variable. But, I've never worked on the borrow-checker before, so could someone help me get started in the right direction? Thanks!</p>



<a name="212982607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/adding%20a%20note%20to%20borrow-check%20error/near/212982607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/adding.20a.20note.20to.20borrow-check.20error.html#212982607">(Oct 11 2020 at 21:31)</a>:</h4>
<p><span class="user-mention" data-user-id="119031">@Esteban Küber</span> is probably the person to ask</p>



<a name="212982658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/adding%20a%20note%20to%20borrow-check%20error/near/212982658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/adding.20a.20note.20to.20borrow-check.20error.html#212982658">(Oct 11 2020 at 21:32)</a>:</h4>
<p>And/or someone who works on MIR maybe?</p>



<a name="218143195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/adding%20a%20note%20to%20borrow-check%20error/near/218143195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/adding.20a.20note.20to.20borrow-check.20error.html#218143195">(Nov 28 2020 at 02:42)</a>:</h4>
<p><span class="user-mention" data-user-id="119031">@Esteban Küber</span> Do you think you could give me some mentoring instructions on <a href="https://github.com/rust-lang/rust/issues/77834">#77834</a> or direct me to someone else who can? Thank you so much!</p>



<a name="218235036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/adding%20a%20note%20to%20borrow-check%20error/near/218235036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/adding.20a.20note.20to.20borrow-check.20error.html#218235036">(Nov 29 2020 at 23:00)</a>:</h4>
<p><span class="user-mention" data-user-id="307537">@Camelid</span> I'm not an expert, but maybe these can help you get started:</p>
<ul>
<li><a href="https://github.com/rust-lang/rust/tree/master/compiler/rustc_mir/src/borrow_check">https://github.com/rust-lang/rust/tree/master/compiler/rustc_mir/src/borrow_check</a> is the borrow checker implementation</li>
<li>The rustc-dev-guide section gives a good intro about the borrow checker as a whole: <a href="https://rustc-dev-guide.rust-lang.org/borrow_check.html">https://rustc-dev-guide.rust-lang.org/borrow_check.html</a></li>
<li>All of the diagnostics (I think) in the borrow checker are emitted from <a href="https://github.com/rust-lang/rust/tree/master/compiler/rustc_mir/src/borrow_check/diagnostics">https://github.com/rust-lang/rust/tree/master/compiler/rustc_mir/src/borrow_check/diagnostics</a> (which is a fairly large module). There are a bunch of methods and types that are used to emit different borrow checker errors. You can probably grep for the specific error you want to improve and then look to see where it is called from to find the part of the borrow checker you care about.</li>
</ul>



<a name="218235194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/adding%20a%20note%20to%20borrow-check%20error/near/218235194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/adding.20a.20note.20to.20borrow-check.20error.html#218235194">(Nov 29 2020 at 23:05)</a>:</h4>
<p>I haven't really looked at the code, but my guess is that the hardest part of the PR will be detecting the specific case you want to add a note for, since it looks like it's currently just handled by the standard "multiple mutable borrows" path. Once you've detected it, you would just want to modify the code path to add a note.</p>



<a name="218235406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/adding%20a%20note%20to%20borrow-check%20error/near/218235406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/adding.20a.20note.20to.20borrow-check.20error.html#218235406">(Nov 29 2020 at 23:11)</a>:</h4>
<p>It sounds like you would need to identify places in the MIR where the conflicting borrows are from expressions in two different arguments of the same function call (e.g. self and something else). Notably, the borrows could be in subexpressions of one of the arguments. For example, you could have an arbitrary self type or the argument could be something like <code>self.bar()</code> instead of just <code>&amp;mut self</code>...</p>



<a name="218235456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/adding%20a%20note%20to%20borrow-check%20error/near/218235456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/adding.20a.20note.20to.20borrow-check.20error.html#218235456">(Nov 29 2020 at 23:12)</a>:</h4>
<p>Unfortunately, I don't really know how one would go about actually implementing that. You would probably want to ask someone like matthewjasper, eddyb, or nikomatsakis.</p>



<a name="218235485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/adding%20a%20note%20to%20borrow-check%20error/near/218235485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/adding.20a.20note.20to.20borrow-check.20error.html#218235485">(Nov 29 2020 at 23:13)</a>:</h4>
<p>This issue sounds like a great way to learn your way around the MIR and borrow check diagnostics code <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="218240394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/adding%20a%20note%20to%20borrow-check%20error/near/218240394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/adding.20a.20note.20to.20borrow-check.20error.html#218240394">(Nov 30 2020 at 01:19)</a>:</h4>
<p>btw there is also <a class="stream" data-stream-id="147480" href="/#narrow/stream/147480-t-compiler.2Fwg-diagnostics">#t-compiler/wg-diagnostics</a></p>



<a name="218242767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/adding%20a%20note%20to%20borrow-check%20error/near/218242767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/adding.20a.20note.20to.20borrow-check.20error.html#218242767">(Nov 30 2020 at 02:26)</a>:</h4>
<p>Alright, thanks for the help mark-i-m!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>